/// FileName: favorite_grid_view
/// Author: admin
/// Date: 2021-08-25 11:15
/// Description: 收藏页面的宫格组件, 简单宫格封装

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:high_help_apps/common/values/define.dart';

class BuilderGridView extends StatelessWidget {
  BuilderGridView({
    required this.builder,
    required this.length,
    this.crossCount,
    this.isShowTitle,
    this.galleryTitle,
    this.childAspectRatio,
    this.crossAxisSpacing,
    this.mainAxisSpacing
  });

  /// 构造器
  final builderFunction builder;

  /// 数据长度
  final int length;

  /// 一行的多少
  final int? crossCount;

  /// 标题
  final String? galleryTitle;

  /// 是否展示标题
  final bool? isShowTitle;

  /// 子组件比例
  final double? childAspectRatio;

  /// 从轴间隔
  final double? crossAxisSpacing;

  /// 主轴间隔
  final double? mainAxisSpacing;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          isShowTitle == null || isShowTitle == true ? Container(
            margin: EdgeInsets.fromLTRB(
                15.r, 15.r, 0, 15.r),
            child: Text(
              this.galleryTitle ?? 'You might like:',
              style: TextStyle(
                  fontSize: 18.sp, fontWeight: FontWeight.bold),
            ),
          ) : Container(),
          GridView.builder(
            padding: EdgeInsets.all(10.r),
            shrinkWrap: true,
            physics: new NeverScrollableScrollPhysics(),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: this.crossCount ?? 2,
                crossAxisSpacing: this.crossAxisSpacing ?? 15.r,
                mainAxisSpacing: this.mainAxisSpacing ?? 15.r,
                childAspectRatio: this.childAspectRatio ?? 0.6),
            itemCount: this.length,
            itemBuilder: this.builder,
          )
        ],
      ),
    );
  }
}

